"""
Agent智能API
职位推荐、简历分析、面试建议
"""
from flask import Blueprint, request, jsonify
from agent_system.recruiter_agent import RecruiterAgent
from agent_system.analyzer_agent import AnalyzerAgent
from agent_system.advisor_agent import AdvisorAgent
from rag_system.vector_store import VectorStore
from rag_system.retriever import RAGRetriever

agent_bp = Blueprint('agent', __name__, url_prefix='/api/agent')
vector_store = VectorStore()
rag_retriever = RAGRetriever(vector_store)
recruiter_agent = RecruiterAgent(rag_retriever)
analyzer_agent = AnalyzerAgent(rag_retriever)
advisor_agent = AdvisorAgent()

# 初始化后打印日志确认使用通义千问
print("AI服务已初始化 - 使用通义千问API")

@agent_bp.route('/recommend_jobs', methods=['POST'])
def recommend_jobs():
    data = request.get_json()
    content = data.get('content')
    n_results = int(data.get('n_results', 5))
    if not content:
        return jsonify({'error': 'content为必填'}), 400
    results = recruiter_agent.recommend_jobs(content, n_results)
    return jsonify({'results': results})

@agent_bp.route('/analyze_resume', methods=['POST'])
def analyze_resume():
    data = request.get_json()
    content = data.get('content')
    if not content:
        return jsonify({'error': 'content为必填'}), 400
    result = analyzer_agent.analyze_resume(content)
    return jsonify(result)

@agent_bp.route('/interview_advice', methods=['POST'])
def interview_advice():
    data = request.get_json()
    content = data.get('content')
    if not content:
        return jsonify({'error': 'content为必填'}), 400
    result = advisor_agent.generate_advice(content)
    return jsonify({'advice': result})
